Ext.define('Intranet.Desktop.view.TeamGroupsPanel', {
    
    extend: 'Ext.panel.Panel', 
    alias: 'widget.desktop_teamgroupspanel',
    
    layout: 'column',
    
    title: 'Team Groups',
    
    id: 'teamgroups_panel',
    
    width: 1100,
    collapsible: true,
    
    defaults: {
        style: 'margin: 10px 5px;',
        border: false
    },

    items: [{
            columnWidth: 0.5,
            
            defaults: {
                style: 'margin-bottom: 10px;'
            },
            
            items: []
            
    }, {
            columnWidth: 0.5,
            
            defaults: {
                style: 'margin-bottom: 10px;'
            },
            
            items: []
    }],

    initComponent : function()
    {
        var thisComponent = this;
        
        this.callParent(arguments);
        
        Ext.Ajax.request({
            url: '/src/public/module/modulesusers/getModules',

            success: function(response){

                var data = Ext.decode(response.responseText);

                if(data.success === 'true')
                {
                    thisComponent.items.items[0].removeAll();
                    thisComponent.items.items[1].removeAll();
                    
                    var index = 0;

                    for (var i = 0; i < data.modules.length; i++)
                    {                        
                        if(data.modules[i].group_id === '2')
                        {
                            var module_name = data.modules[i].key_name;

                            var item = Ext.widget(module_name + '_MiniView');

                            thisComponent.items.items[index % 2].add(item);

                            index++;
                        }
                    }
                }
                else
                {
                    Ext.Msg.alert('Get Modules failed', data.msg);
                }

            }
        }); 
    }

});


